package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Department;
import cn.wolfcode.rbac.service.DepartmentService;
import cn.wolfcode.rbac.util.QueryObject;
import cn.wolfcode.rbac.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("department")
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;

    @RequestMapping("/list")
    @RequiredPermission({"部门列表","department:list"})
    public String list(QueryObject qo, Model model){
        model.addAttribute("result",departmentService.query(qo));
        return "department/list";
    }

    @RequestMapping("saveOrUpdate")
    @RequiredPermission({"部门新增或编辑","department:saveOrUpdate"})
    public String saveOrUpdate(Department department){
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list.do";
    }

    @RequestMapping("input")

    public String input(Model model,Long id){
        if(id != null){
            Department d = departmentService.get(id);
            model.addAttribute("entity",d);
        }
        return "department/input";
    }

    @RequestMapping("/delete")
    @RequiredPermission({"部门删除","department:delete"})
    public String delete(Long id){
        departmentService.delete(id);
        return "redirect:/department/list.do";
    }
}
